﻿using System;
using System.Collections.Generic;
using System.Text;



namespace LibIpMsgNet
{
    public class Consts
    {
        public const int   MAX_NAMEBUF              = 50;
        public const int   MAX_SOCKBUF              = 65536;
        public const int   MAX_UDPBUF               = 16384;

        public const char FILELIST_SEPARATOR = '\a';
        public const char HOSTLIST_SEPARATOR = '\a';
        public const char HOSTLIST_DUMMY = '\b';

    }

    public class IPMSG_DEF
    {
        /*  IP Messenger Communication Protocol version 1.2 define  */

        /* header */
        public const ulong IPMSG_VERSION            = 0x0001;
        public const ulong IPMSG_DEFAULT_PORT       = 0x0979;

        /*  command  */
        public const ulong IPMSG_NOOPERATION        = 0x00000000UL;

        public const ulong IPMSG_BR_ENTRY           = 0x00000001UL;
        public const ulong IPMSG_BR_EXIT            = 0x00000002UL;
        public const ulong IPMSG_ANSENTRY           = 0x00000003UL;
        public const ulong IPMSG_BR_ABSENCE         = 0x00000004UL;

        public const ulong IPMSG_BR_ISGETLIST       = 0x00000010UL;
        public const ulong IPMSG_OKGETLIST          = 0x00000011UL;
        public const ulong IPMSG_GETLIST            = 0x00000012UL;
        public const ulong IPMSG_ANSLIST            = 0x00000013UL;
        public const ulong IPMSG_BR_ISGETLIST2      = 0x00000018UL;

        public const ulong IPMSG_SENDMSG            = 0x00000020UL;
        public const ulong IPMSG_RECVMSG            = 0x00000021UL;
        public const ulong IPMSG_READMSG            = 0x00000030UL;
        public const ulong IPMSG_DELMSG             = 0x00000031UL;
        public const ulong IPMSG_ANSREADMSG         = 0x00000032UL;

        public const ulong IPMSG_GETINFO            = 0x00000040UL;
        public const ulong IPMSG_SENDINFO           = 0x00000041UL;

        public const ulong IPMSG_GETABSENCEINFO     = 0x00000050UL;
        public const ulong IPMSG_SENDABSENCEINFO    = 0x00000051UL;

        public const ulong IPMSG_GETFILEDATA        = 0x00000060UL;
        public const ulong IPMSG_RELEASEFILES       = 0x00000061UL;
        public const ulong IPMSG_GETDIRFILES        = 0x00000062UL;

        public const ulong IPMSG_GETPUBKEY          = 0x00000072UL;
        public const ulong IPMSG_ANSPUBKEY          = 0x00000073UL;

        /*  option for all command  */
        public const ulong IPMSG_ABSENCEOPT         = 0x00000100UL;
        public const ulong IPMSG_SERVEROPT          = 0x00000200UL;
        public const ulong IPMSG_DIALUPOPT          = 0x00010000UL;
        public const ulong IPMSG_FILEATTACHOPT      = 0x00200000UL;
        public const ulong IPMSG_ENCRYPTOPT         = 0x00400000UL;

        /*  option for send command  */
        public const ulong IPMSG_SENDCHECKOPT       = 0x00000100UL;
        public const ulong IPMSG_SECRETOPT          = 0x00000200UL;
        public const ulong IPMSG_BROADCASTOPT       = 0x00000400UL;
        public const ulong IPMSG_MULTICASTOPT       = 0x00000800UL;
        public const ulong IPMSG_NOPOPUPOPT         = 0x00001000UL;
        public const ulong IPMSG_AUTORETOPT         = 0x00002000UL;
        public const ulong IPMSG_RETRYOPT           = 0x00004000UL;
        public const ulong IPMSG_PASSWORDOPT        = 0x00008000UL;
        public const ulong IPMSG_NOLOGOPT           = 0x00020000UL;
        public const ulong IPMSG_NEWMUTIOPT         = 0x00040000UL;
        public const ulong IPMSG_NOADDLISTOPT       = 0x00080000UL;
        public const ulong IPMSG_READCHECKOPT       = 0x00100000UL;
        public const ulong IPMSG_SECRETEXOPT        = (IPMSG_READCHECKOPT | IPMSG_SECRETOPT);

        /* encryption flags for encrypt command */
        public const ulong IPMSG_RSA_512			= 0x00000001UL;
        public const ulong IPMSG_RSA_1024			= 0x00000002UL;
        public const ulong IPMSG_RSA_2048			= 0x00000004UL;
        public const ulong IPMSG_RC2_40			    = 0x00001000UL;
        public const ulong IPMSG_RC2_128			= 0x00004000UL;
        public const ulong IPMSG_RC2_256			= 0x00008000UL;
        public const ulong IPMSG_BLOWFISH_128		= 0x00020000UL;
        public const ulong IPMSG_BLOWFISH_256		= 0x00040000UL;
        public const ulong IPMSG_SIGN_MD5			= 0x10000000UL;

        /* compatibilty for Win beta version */
        public const ulong IPMSG_RC2_40OLD			= 0x00000010UL;	// for beta1-4 only
        public const ulong IPMSG_RC2_128OLD		    = 0x00000040UL;	// for beta1-4 only
        public const ulong IPMSG_BLOWFISH_128OLD	= 0x00000400UL;	// for beta1-4 only
        public const ulong IPMSG_RC2_40ALL			= (IPMSG_RC2_40|IPMSG_RC2_40OLD);
        public const ulong IPMSG_RC2_128ALL		    = (IPMSG_RC2_128|IPMSG_RC2_128OLD);
        public const ulong IPMSG_BLOWFISH_128ALL	= (IPMSG_BLOWFISH_128|IPMSG_BLOWFISH_128OLD);

        /* file types for fileattach command */
        public const ulong IPMSG_FILE_REGULAR		= 0x00000001UL;
        public const ulong IPMSG_FILE_DIR			= 0x00000002UL;
        public const ulong IPMSG_FILE_RETPARENT	    = 0x00000003UL;	// return parent directory
        public const ulong IPMSG_FILE_SYMLINK		= 0x00000004UL;
        public const ulong IPMSG_FILE_CDEV			= 0x00000005UL;	// for UNIX
        public const ulong IPMSG_FILE_BDEV			= 0x00000006UL;	// for UNIX
        public const ulong IPMSG_FILE_FIFO			= 0x00000007UL;	// for UNIX
        public const ulong IPMSG_FILE_RESFORK		= 0x00000010UL;	// for Mac

        /* file attribute options for fileattach command */
        public const ulong IPMSG_FILE_RONLYOPT		= 0x00000100UL;
        public const ulong IPMSG_FILE_HIDDENOPT	    = 0x00001000UL;
        public const ulong IPMSG_FILE_EXHIDDENOPT	= 0x00002000UL;	// for MacOS X
        public const ulong IPMSG_FILE_ARCHIVEOPT	= 0x00004000UL;
        public const ulong IPMSG_FILE_SYSTEMOPT	    = 0x00008000UL;

        /* extend attribute types for fileattach command */
        public const ulong IPMSG_FILE_UID			= 0x00000001UL;
        public const ulong IPMSG_FILE_USERNAME		= 0x00000002UL;	// uid by string
        public const ulong IPMSG_FILE_GID			= 0x00000003UL;
        public const ulong IPMSG_FILE_GROUPNAME	    = 0x00000004UL;	// gid by string
        public const ulong IPMSG_FILE_PERM			= 0x00000010UL;	// for UNIX
        public const ulong IPMSG_FILE_MAJORNO		= 0x00000011UL;	// for UNIX devfile
        public const ulong IPMSG_FILE_MINORNO		= 0x00000012UL;	// for UNIX devfile
        public const ulong IPMSG_FILE_CTIME		    = 0x00000013UL;	// for UNIX
        public const ulong IPMSG_FILE_MTIME		    = 0x00000014UL;
        public const ulong IPMSG_FILE_ATIME		    = 0x00000015UL;
        public const ulong IPMSG_FILE_CREATETIME	= 0x00000016UL;
        public const ulong IPMSG_FILE_CREATOR		= 0x00000020UL;	// for Mac
        public const ulong IPMSG_FILE_FILETYPE		= 0x00000021UL;	// for Mac
        public const ulong IPMSG_FILE_FINDERINFO	= 0x00000022UL;	// for Mac
        public const ulong IPMSG_FILE_ACL			= 0x00000030UL;
        public const ulong IPMSG_FILE_ALIASFNAME	= 0x00000040UL;	// alias fname
        public const ulong IPMSG_FILE_UNICODEFNAME	= 0x00000041UL;	// UNICODE fname


        /*  end of IP Messenger Communication Protocol version 1.2 define  */


        /*  IP Messenger for Windows  internal define  */
        public const ulong IPMSG_REVERSEICON		= 0x0100;
        public const ulong IPMSG_TIMERINTERVAL		= 500;
        public const ulong IPMSG_ENTRYMINSEC		= 5;
        public const ulong IPMSG_GETLIST_FINISH		= 0;

        public const ulong IPMSG_BROADCAST_TIMER	= 0x0101;
        public const ulong IPMSG_SEND_TIMER			= 0x0102;
        public const ulong IPMSG_LISTGET_TIMER		= 0x0104;
        public const ulong IPMSG_LISTGETRETRY_TIMER	= 0x0105;
        public const ulong IPMSG_ENTRY_TIMER		= 0x0106;
        public const ulong IPMSG_DUMMY_TIMER		= 0x0107;
        public const ulong IPMSG_RECV_TIMER			= 0x0108;
        public const ulong IPMSG_ANS_TIMER			= 0x0109;

        public const ulong IPMSG_NICKNAME			= 1;
        public const ulong IPMSG_FULLNAME			= 2;

        public const ulong IPMSG_NAMESORT			= 0x00000000;
        public const ulong IPMSG_IPADDRSORT	    	= 0x00000001;
        public const ulong IPMSG_HOSTSORT			= 0x00000002;
        public const ulong IPMSG_NOGROUPSORTOPT	    = 0x00000100;
        public const ulong IPMSG_ICMPSORTOPT		= 0x00000200;
        public const ulong IPMSG_NOKANJISORTOPT	    = 0x00000400;
        public const ulong IPMSG_ALLREVSORTOPT		= 0x00000800;
        public const ulong IPMSG_GROUPREVSORTOPT	= 0x00001000;
        public const ulong IPMSG_SUBREVSORTOPT		= 0x00002000;

        /* functions */
        public static ulong GET_MODE(ulong command)
        {
            return (command & 0x000000ffUL);
        }

        public static ulong GET_OPT(ulong command)
        {
            return (command & 0xffffff00UL);
        }

    }
}
